package com.briup.smartcity_group1.web.controller.auth;

import com.briup.smartcity_group1.bean.basic.Comment;
import com.briup.smartcity_group1.consts.BeanNameConsts;
import com.briup.smartcity_group1.consts.DataMessageConsts;
import com.briup.smartcity_group1.service.ICommentService;
import com.briup.smartcity_group1.utils.result.Result;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * 评论信息模块控制器
 *
 * @author WangChen
 * @date 2023/1/6 9:32
 */
@RestController
@RequestMapping(BeanNameConsts.COMMENT)
public class CommentController {

    @Autowired
    private ICommentService service;

    @GetMapping("/page")
    public PageInfo<Comment> getPageByKeyword(@RequestParam(required = true,defaultValue = "1") Integer pageNum,
                                              @RequestParam(required = true,defaultValue = "3") Integer pageSize,
                                              @RequestParam(required = true) String keywords){

        return service.pageQuery(pageNum,pageSize, keywords);

    }

    @DeleteMapping
    public void deleteById(@RequestParam(required = true) Integer id){
        service.deleteById(id);
        Result.setDataMessage(DataMessageConsts.COMMENT_DELETE_SUCCESS);
    }

    @DeleteMapping(value = "/batch")
    public void batchDeleteByIds(@RequestParam(required = true) Integer[] ids){

        //将Integer数组转换为int数组
        int[] intIds = new int[ids.length];

        for (int i = 0; i < ids.length; i++) {
            intIds[i] = ids[i];
        }
        service.batchDelete(intIds);
        Result.setDataMessage(DataMessageConsts.CATEGORY_DELETE_SUCCESS);
    }

    @PutMapping(value = "/check")
    public void check(@RequestParam(required = true) Integer id,
                      @RequestParam(required = true) Integer status){
        service.checkComment(id,status);
        Result.setDataMessage(DataMessageConsts.COMMENT_CHECK_SUCCESS);
    }


}
